- content_for :head do
  = javascript_include_tag  'mootools-1.2.1-core.js'
  = javascript_include_tag  'mootools-1.2-more.js'
  = javascript_include_tag  'partnerships_updatation'
  = javascript_include_tag  'galleryeditsearchform'
  = javascript_include_tag  'tiny_mce/tiny_mce.js'
  = stylesheet_link_tag 'pagination'
  %script{:type => "text/javascript"}
    = "tinyMCE.init({"
    = '   mode : "textareas",'
    = '   theme : "advanced",'
    = '   plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",'
    = '   theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,image,|,forecolor,backcolor",'
    = '   theme_advanced_buttons2 : "",'
    = '   theme_advanced_toolbar_location : "top",'
    = '   theme_advanced_toolbar_align : "left",'
    = '   template_external_list_url : "/javascripts/tiny_mce/lists/template_list.js",'
    = '   external_link_list_url : "/javascripts/tiny_mce/lists/link_list.js",'
    = '   external_image_list_url : "/javascripts/tiny_mce/lists/image_list.js",'
    = '   media_external_list_url : "/javascripts/tiny_mce/lists/media_list.js",'
    = "});"

%input#form_authenticity_token{:type => 'hidden', :value => form_authenticity_token, :name => "authenticty_token"}
%input#gallery_id{:type => 'hidden', :value => @gallery.id, :name => "gallery_id"}

%h1.page_title Edit Gallery
%table.edit_gallery
  - form_for @gallery, :method => :update do |form| 
    %tr
      %td.field_title Name:
      %td.field= form.text_field :name
      %td.error= error_message_on :gallery, :name
    %tr
      %td.field_title Description:
      %td.field= form.text_area :description
      %td.error= error_message_on :gallery, :text
    %tr
      %td.field_title Pricing:
      %td.field
        %select{:name => "gallery[price_list_id]", :disabled => ("disabled" unless @gallery.gallery_template.handles_add_to_cart?)}
          %option{:value => ''} not purchasable
          - @price_lists.each do |price_list|
            %option{:value => price_list.id, :selected => ('selected' if price_list == @gallery.price_list)}= price_list.name
        - unless @gallery.gallery_template.handles_add_to_cart?
          %span.warning The template assigned to this gallery doesn't support add_to_cart. Choose a different template if you want people to be able to add items in this gallery to their cart.
      %td.error
        = error_message_on :gallery, :price_list
    %tr
      %td.field_title Template:
      %td.field
        %select{:name => "gallery[gallery_template_id]"}
          - @gallery_templates.each do |gallery_template|
            %option{:value => gallery_template.id, :selected => ('selected' if gallery_template == @gallery.gallery_template)}= gallery_template.name
      %td.error
        = error_message_on :gallery, :gallery_templete
    %tr
      %td.field_title Pages:
      %td.field
        = select_tag("gallery[page_ids][]", options_for_select(@pages.collect { |cat| [cat.title, cat.id] }, @gallery.pages.collect { |cat| cat.id}), {:multiple=>true, :size=>6})
      %td.error
        = error_message_on :gallery, :page
    %tr
      %td.field_title Invisible?
      %td.field
        = check_box_tag("gallery[invisible]", 1, @gallery.invisible?)
        Won't show up in search results or anywhere else
      %td.error= error_message_on :gallery, :invisible
    %tr
      %td.field_title For Proofing?
      %td.field
        = check_box_tag("gallery[for_proofing]", 1, @gallery.for_proofing?, :disabled => ("disabled" unless @gallery.gallery_template.handles_proofing?))
        For clients to proof photos.
        - unless @gallery.gallery_template.handles_proofing?
          %span.warning The template assigned to this gallery doesn't support proofing. Choose a different template if you want clients to be able to proof items in this gallery.
      %td.error= error_message_on :gallery, :for_proofing
    %tr
      %td.field_title Approved?
      %td.field
        = check_box_tag("gallery[is_approved]", 1, @gallery.is_approved?, :disabled => ("disabled" unless @gallery.for_proofing? and @gallery.gallery_template.handles_proofing?))
        Approved by client or not. Available if "For Proofing" is checked above; save and reload
      %td.error= error_message_on :gallery, :is_approved
    %tr
      %td Thumbnail:
      %td
        %div.gallery_thumbnails
          - @thumbnails.each do |photo|
            %table.gallery_thumbnail
              %tr
                %td.photo
                  %a{:href => photo_url(photo), :title => (photo.caption ? photo.caption : photo.filename), :alt => (photo.caption ? photo.caption : photo.filename)}
                    %img.photo_thumb{:src => photo.public_filename(:thumb), :title => (photo.caption ? photo.caption : photo.filename), :alt => (photo.caption ? photo.caption : photo.filename)}
              %tr
                %td.check_box
                  = radio_button_tag("gallery[photo_id]", photo.id, photo == @gallery.photo)
    %tr
      %td.field_title Clients:
      %td.field
        = select_tag("gallery[user_ids][]", options_for_select(@users.collect { |cat| [cat.login, cat.id] }, @gallery.users.collect { |cat| cat.id}), {:multiple=>true, :size=>6})
    %tr
      %td.field_title Save:
      %td.submit= submit_tag 'Update'
%table.edit_gallery  
  %tr
    %td.field_title Videos:
    %td.field
      #videos.gallery_items{:style => ("display:none" unless @gallery.gallery_template.handles_videos?)}
        = render :partial => 'videos'
      - unless @gallery.gallery_template.handles_videos?
        %span.warning The template assigned to this gallery doesn't the viewing of videos. Choose a different template if you want clients to be able to see videos in this gallery.
  %tr
    %td.field_title Photos:
    %td.field
      #photos.gallery_items{:style => ("display:none" unless @gallery.gallery_template.handles_photos?)}
        = render :partial => 'photos'
      %div.gallery_edit_photo_search{:style => ("display:none" unless @gallery.gallery_template.handles_photos?)}
        = text_field_tag :term, params[:term], :class => "gallery_edit_photo_search_field"
        %a.search{:href => search_photos_url, :title => "Search photos"} Search
      - unless @gallery.gallery_template.handles_photos?
        %span.warning The template assigned to this gallery doesn't the viewing of photos. Choose a different template if you want clients to be able to see photos in this gallery.
  - form_for @gallery, galleries_url, :html => {:method => :delete} do |form|      
    %input{:name => "gallery[dummy]", :value => "dummy value. here so params[:gallery] is instantiated for the delete photo options", :type => "hidden"}
    %tr
      %td.field_title Delete:
      %td.field
        Ok, so you want to delete this gallery. If you want, you can choose these additional options:
        %br
        %br
        = check_box_tag("gallery[destroy_all_photos]")
        Delete all photos in this gallery as well
        %br
        %span{:style => "padding-left: 15px;"}
          = check_box_tag("gallery[destroy_all_photos_except]")
          Except those in other galleries
        %br
        = check_box_tag("gallery[destroy_all_videos]")
        Delete all videos in this gallery as well
        %br
        %span{:style => "padding-left: 15px;"}
          = check_box_tag("gallery[destroy_all_videos_except]")
          Except those in other galleries
        %br
        %br
        = submit_tag 'Delete'